package com.accp.vehiclecare.biz.zbbiz;

import com.accp.vehiclecare.dao.zbdao.*;
import com.accp.vehiclecare.pojo.*;
import com.accp.vehiclecare.vo.zbvo.StaffVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StaffBiz {
    @Autowired(required = false)
    private EmployeeMapper edao;

    @Autowired(required = false)
    private ShopMapper sdao;

    @Autowired(required = false)
    private DepartmentMapper ddao;

    @Autowired(required = false)
    private GroupMapper gdao;

    @Autowired(required = false)
    private StationMapper stdao;

    @Autowired(required = false)
    private JurisdictionMapper jdao;
    /**
     * 分页查询员工信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public PageInfo<StaffVo> queryAll(Integer pageNum, Integer pageSize) {
        System.out.println(pageNum+"=="+pageSize);
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<StaffVo>(edao.SelectAll());
    }

    /**
     * 根据id删除员工
     * @param sid
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean deleteStaff(Integer sid){
        return 0!=edao.deleteByPrimaryKey(sid);
    }

    /**
     * 新增员工
     * @param employee
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean addStaff(Employee employee){
        return 0!=edao.insertSelective(employee);
    }
    /**
     * 查询门店
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<Shop> queryShop() {
        return sdao.SelectShop();
    }

    /**
     * 根据门店id查询部门
     * @param sid
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<Department> queryDep(Integer sid) {
        return ddao.SelectDep(sid);
    }

    /**
     * 根据部门id查询部门组
     * @param did
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<Group> queryGrou(Integer did) {
        return gdao.SelectGroup(did);
    }

    /**、
     * 查询全部的岗位
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<Station> queryStat() {
        return stdao.SelectAllStaion();
    }

    /**
     * 查询全部的角色
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<Jurisdiction> queryJur() {
        return jdao.SelectJur();
    }

    /**
     * 根据用户id查询用户信息
     * @param eid
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public Employee queryEmpBy(Integer eid) {
        return edao.selectByPrimaryKey(eid);
    }
    /**
     * 修改员工信息
     * @param employee
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean modifyStaff(Employee employee){
        return 0!=edao.updateByPrimaryKeySelective(employee);
    }

    /**
     * 模糊查询用户
     * @param pageNum
     * @param pageSize
     * @param eno
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public PageInfo<StaffVo> queryLike(Integer pageNum, Integer pageSize,String eno) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<StaffVo>(edao.SelectLike(eno));
    }
}
